﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.IO;
using System.Windows.Forms;
using System.Xml;
using YArchitech.Controls;
using YArchitech.LIB;
using HYOpeningCommon.Public;
using HYOpeningDesignInput.Public;

namespace HYOpeningDesignInput.ConfigForm
{
	public partial class OpeningDesignSetReportForm : ConfigDataBaseForm
	{
		public OpeningDesignSetReportForm()
		{
			this.InitializeComponent();
			base.SetFormLocation(this.strXmlPath);
			Dictionary<string, int> dictionary = new Dictionary<string, int>();
			if (Interface.GetXmlData(ref dictionary))
			{
				this.CircleOutSizeTextBox.Text = dictionary["CircleOpeningOutSize"].ToString();
				this.RectOutSizeTextBox1.Text = dictionary["RectOpeningOutSize"].ToString();
				this.ComTolerance.Text = dictionary["CompositeTolerance"].ToString();
				this.ComOutSize.Text = dictionary["CompositeOutSize"].ToString();
			}
		}

		private void BtnOK_Click(object sender, EventArgs e)
		{
			try
			{
				XmlDocument xmlDocument = new XmlDocument();
				if (File.Exists(this.strXmlPath))
				{
					XmlReaderSettings xmlReaderSettings = new XmlReaderSettings();
					xmlReaderSettings.IgnoreComments = true;
					XmlReader xmlReader = XmlReader.Create(this.strXmlPath, xmlReaderSettings);
					xmlDocument.Load(xmlReader);
					XmlElement documentElement = xmlDocument.DocumentElement;
					this.SetAttibute(documentElement);
					xmlReader.Close();
				}
				else
				{
					XmlDeclaration newChild = xmlDocument.CreateXmlDeclaration("1.0", "gb2312", null);
					xmlDocument.AppendChild(newChild);
					XmlElement xmlElement = xmlDocument.CreateElement("HistoryData");
					xmlDocument.AppendChild(xmlElement);
					this.SetAttibute(xmlElement);
				}
				xmlDocument.Save(this.strXmlPath);
				base.Close();
			}
			catch (Exception)
			{
				base.Close();
				throw;
			}
		}

		private void SetAttibute(XmlElement xmlElement)
		{
			xmlElement.SetAttribute("LocationX", base.Location.X.ToString());
			xmlElement.SetAttribute("LocationY", base.Location.Y.ToString());
			xmlElement.SetAttribute("CircleOpeningOutSize", this.CircleOutSizeTextBox.Text);
			xmlElement.SetAttribute("RectOpeningOutSize", this.RectOutSizeTextBox1.Text);
			xmlElement.SetAttribute("CompositeTolerance", this.ComTolerance.Text);
			xmlElement.SetAttribute("CompositeOutSize", this.ComOutSize.Text);
		}

		private void BtnCancel_Click(object sender, EventArgs e)
		{
			base.Close();
		}

		private string strXmlPath = Product.UserDataLocation + "\\OpeningDesignSetReportForm.xml";

		private YJKTextBox hyTextBox1;

		private YJKTextBox circleTextBox;

		private YJKTextBox CircleOutText;

		private YJKTextBox RectOutSizeText;

		private YJKTextBox CircleOutTextBox;

		private YJKTextBox RectOutSizeTextBox;

		private YJKTextBox ComOutSize1;

		private YJKTextBox CircleOutTextBox1;

		private YJKTextBox CircleOutSizeText1;

		private YJKTextBox RectOutTextBox;
	}
}
